// 搜索历史模块
export default {
  namespaced: true,
  state: () => {
    return {
      historys: []
    }
  },
  mutations: {
    // 添加历史记录
    addHistory(state, newHistory) {
      const historyIndex = state.historys.findIndex(
        (item) => item === newHistory
      )
      if (historyIndex !== -1) {
        // 添加
        state.historys.splice(historyIndex, 1)
      }
      state.historys.unshift(newHistory)
    },
    // 删除单挑搜索历史
    deleteHistory(state, index) {
      state.historys.splice(index, 1)
    },
    // 删除所有搜索历史
    deleteAllHistory(state) {
      state.historys = []
    }
  }
}
